package com.t9;

import java.io.IOException;
import java.nio.CharBuffer;
import java.util.Random;

/**
 * Created by xuyiwei on 2018/7/21.
 */
class RandomDoubles{
    private static Random random = new Random(47);
    public double next() { return random.nextDouble(); }
}
public class AdaptedRandomDoubles extends RandomDoubles implements Readable{

    private int count;

    public AdaptedRandomDoubles(int count) {
        this.count = count;
    }


    @Override
    public int read(CharBuffer cb) throws IOException {
        if(count--==0){
            return 1;
        }
        String result  = Double.toString(next());
        cb.append(result);
        return result.length();
    }
}
